package leecode

func longestAlternatingSubarray(nums []int, threshold int) int {
	result := 0
	for i := 0; i < len(nums); i++ {
		if nums[i]%2 == 0 && nums[i] <= threshold {
			j := i + 1
			for j < len(nums) && nums[j]%2 != nums[j-1]%2 && nums[j] <= threshold {
				j++
			}
			result = max(result, j-i)
		}
	}
	return result
}
